package com.example.enterprise.service;

import com.example.enterprise.dao.PictureMapper;


import com.example.enterprise.entity.Picture;
import com.example.enterprise.entity.PictureExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static com.example.enterprise.util.EnterpriseConstant.*;

@Service
public class PictureService {



    @Autowired
    private PictureMapper pictureMapper;




    public int insertPic(int picType,int affiliation,String picAddress,String picInfo,int status){
        Picture pic=new Picture();
        pic.setPictureType(picType);
        pic.setAffiliation(affiliation);
        pic.setPictureAddress(picAddress);
        pic.setPictureInfo(picInfo);
        pic.setStatus(status);
        return pictureMapper.insertSelective(pic);
    }

    public List<Picture> findPicByAffiliation(int seLogId){
        PictureExample example=new PictureExample();
        List<Integer> seLogIds =new ArrayList<>();
        seLogIds.add(seLogId);

        example.createCriteria().andAffiliationIn(seLogIds);

        List<Picture> pictures=pictureMapper.selectByExample(example);

        return pictures;
    }
    //删除picture即将status改为Delete_Picture=1
    public int changeDeleteStatus(int pictureId){

        Picture picture=pictureMapper.selectByPrimaryKey(pictureId);
        picture.setStatus(Delete_Picture);

        return pictureMapper.updateByPrimaryKeySelective(picture);

    }
    //根据安全日志的id找到附属picture
    public List<Picture> getPicBySeLogId(int logId){

        PictureExample example=new PictureExample();
        //type=Pic_SeLog=4,type=Pic_Not_Delete=1
        example.createCriteria().andAffiliationEqualTo(logId).andPictureTypeEqualTo(Pic_SeLog).andStatusEqualTo(Pic_Not_Delete);
        //时间
        //example.setOrderByClause("date desc");

        return pictureMapper.selectByExample(example);

    }
}
